<?php
error_reporting(E_ALL);
$PHP_SELF = $_SERVER['PHP_SELF'];
srand((double)microtime()*1000000);
//require_once("./myMidilib/myMidilib001.php");
$save_dir = 'tmp/';
$tt = isset($_POST['tt'])?$_POST['tt']:0;

#$file=(isset($_FILES['mid_upload'])&&$_FILES['mid_upload']['tmp_name']!='')?$_FILES['mid_upload']['tmp_name']:'';
if (isset($_FILES['mid_upload'])){
	$fileMid2txt = $save_dir.rand().'.mid';
	$tmpFileMid2txt=$_FILES['mid_upload']['tmp_name'];
	@move_uploaded_file($tmpFileMid2txt,$fileMid2txt) or die('problems uploading file');
	@chmod($fileMid2txt,0666);
}elseif (isset($_POST['file'])) $fileMid2txt=$_POST['file'];

?>
<h3>mid2txt(3)</h3>
<form enctype="multipart/form-data" action="<?=$PHP_SELF?>" method="post" onsubmit="if (this.mid_upload.value==''){alert('これってmidiファイルじゃないみたいです');return false}">
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" /><!-- 1 MB -->
MIDIファイル(*.mid)をアップロードしてください: <input type="file" name="mid_upload_1" />
<br />
TimestampType:
<input type="radio" name="tt" value="0"<?php if ($tt==0) echo ' checked="checked"'?> /> Absolute
<input type="radio" name="tt" value="1"<?php if ($tt==1) echo ' checked="checked"'?> /> Delta
<br /><br />
<input type="submit" value=" send " />
</div>
</form>
<?php
if (isset($fileMid2txt)){
	/****************************************************************************
	MIDI CLASS CODE
	****************************************************************************/
	require_once('./classes/midi.class.php');

	$midi = new Midi();
	$midi->importMid($fileMid2txt);

	#$str = chr(0x8d) . chr(0xf9) .chr(0x00);
	#$pos = 0;
	#die("LEN:" . _readVarLen($str, &$pos));
?>
<div>
<?php
if(isset($_FILES['mid_upload']['name'])){
echo "File:".$_FILES['mid_upload']['name'];
}
?>

<hr />
<pre>
<?=$midi->getTxt($tt)?>
</pre>
</div>
<?
}
?>